<template>
  <div id="app">
    <div id="nav">
      <router-link to="/">在线</router-link> |
      <router-link to="/control">控制</router-link>
    </div>
    <router-view />
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      baseUrl: "http://47.104.191.212:8091",
      username: "testAdmin",
      password: "123456",
    };
  },
  methods: {
    async login(username, password) {
      let res = await axios.get(
        this.baseUrl + "/xkh/sysuser/find_by_username/" + username
      );
      let userCode = res.data.data;
      res = await axios.post(this.baseUrl + "/auth/userauth/login/pwd", {
        userCode,
        password,
      });
      return res.data.data.tokenValue;
    },
  },
  async mounted() {
    let token = await this.login(this.username, this.password);
    axios.defaults.headers.common["Access_token"] = token;
  },
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

#nav {
  padding: 30px;
}

#nav a {
  font-weight: bold;
  color: #2c3e50;
}

#nav a.router-link-exact-active {
  color: #42b983;
}
</style>
